# 序列化器
from edoego.models import *
from dvadmin.utils.serializers import CustomModelSerializer
from rest_framework import serializers


class InputLogSerializer(CustomModelSerializer):
    #这里是进行了序列化模型及所有的字段
    class Meta:
        model = InputLogModel
        fields = "__all__"

class InputLogCreateUpdateSerializer(CustomModelSerializer):
    #这里是进行了序列化模型及所有的字段
    class Meta:
        model = InputLogModel
        fields = "__all__"

class DeviceSerializer(CustomModelSerializer):
    class Meta:
        model = DeviceModel
        fields = "__all__"
        
class ScanLogSerializer(CustomModelSerializer):
    class Meta:
        model = WeChatUserScanModel
        fields = "__all__"

class CleanerOpenBoxSerializer(CustomModelSerializer):
    class Meta:
        model = CleanerOpenBox
        fields = "__all__"

class BagCodeSerializer(CustomModelSerializer):
    class Meta:
        model = BagCodeModel
        fields = "__all__"

class CleanLogSerializer(CustomModelSerializer):
    # bag_code = serializers.CharField(source='bag_code.bag_code')
    # bag_status = serializers.CharField(source='bag_code.bag_status')
    # user_phone = serializers.CharField(source='user.mobile')
    # user_name = serializers.CharField(source='user.name')
    class Meta:
        model = CleanLogModel
        # fields = ['id','clean_time',"clean_weight","clean_address","clean_status","clean_score","bag_code","bag_status","user_phone","user_name"]
        fields = "__all__"
        depth = 1

class CleanLogInsertSerializer(CustomModelSerializer):
    user = serializers.PrimaryKeyRelatedField(queryset=Users.objects.all())
    admin_user = serializers.PrimaryKeyRelatedField(queryset=Users.objects.all())
    sort_user = serializers.PrimaryKeyRelatedField(queryset=Users.objects.all())
    bag_code = serializers.PrimaryKeyRelatedField(queryset=BagCodeModel.objects.all())
    class Meta:
        model = CleanLogModel
        fields = ['id',"clean_weight","clean_address","clean_status","clean_score","bag_code","user","admin_user","sort_user"]
        

class InputLogSerializer(CustomModelSerializer):
    class Meta:
        model = InputLogModel
        fields = "__all__"
        depth = 1

class WechatUserSerializer(CustomModelSerializer):
    class Meta:
        model = WechatUserModel
        fields = "__all__"

class WeChatUserScoreSerializer(CustomModelSerializer):
    class Meta:
        model = WxChatUserScoreModel
        fields = "__all__"

class WeChatUserInputAndMqttSerializer(CustomModelSerializer):
    class Meta:
        model = WeChatUserInputAndMqtt
        fields = "__all__"


class AppUpdateSerializer(CustomModelSerializer):
    class Meta:
        model = AppUpdateModel
        fields = "__all__"

class SortSerializer(CustomModelSerializer):
    class Meta:
        model = SortModel
        fields = "__all__"


class ApiWeChatLoginSerializer(CustomModelSerializer):
    # 微信用户扫码登录设备传递参数
    phone = serializers.CharField()
    open_id = serializers.CharField()
    device_id = serializers.CharField()
    device_mac = serializers.CharField()
    class Meta:
        model = SortModel
        fields = "__all__"

class QiniuSerializer(CustomModelSerializer):
    class Meta:
        models = QiniuImageUpload
        fields = "__all__"

class ImageSerializer(CustomModelSerializer):
    class Meta:
        model = ImageModel
        fields = "__all__"